package com.util;

/***
 * 类描述: 数字辅助类
 *
 * @author FrodJiang
 * @date 26/06/2017
 */
public class NumberUtil {

    public static boolean isNullOrZero(Integer val) {
        return val == null || val == 0;
    }

    public static boolean isNullOrZero(Double val) {
        return val == null || val == 0;
    }

    public static String toString(Integer val) {
        return val == null ? "" : val.toString();
    }

    public static String toString(Double val) {
        return val == null ? "" : val.toString();
    }

    public static String toStringIncludeZero(Integer val) {
        return val == null || val == 0 ? "" : val.toString();
    }

    public static String toStringIncludeZero(Double val) {
        return val == null || val == 0 ? "" : val.toString();
    }

    public static Double get(Double val, Double def) {
        return val == null ? def : val;
    }

    public static Integer get(Integer val, Integer def) {
        return val == null ? def : val;
    }

    public static Integer toInt(String val, Integer def) throws Exception {
        if (val == null) {
            return def;
        }
        try {
            return Integer.valueOf(val);
        } catch (Exception e) {
            throw new Exception("String转Integer格式错误:" + val);
        }
    }
}
